package com.zly.framework.rbac.model.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 通义返回接口
 * @param <T>
 */
@Data
@Schema(name = "统一返回类")
public class Result<T> {
    @Schema(name = "返回代码")
    private int code;
    @Schema(description = "返回数据")
    private T data;
    @Schema(description = "返回信息")
    private String message;
    @Schema(description = "时间戳")
    private Long timestamp = System.currentTimeMillis();

    @Schema(defaultValue = "成功返回方法")
    public static <T> Result<T> SUCCESS() {
        return Result.SUCCESS(200, "OK", null);
    }

    @Schema(defaultValue = "成功返回方法")
    public static <T> Result<T> SUCCESS(T data) {
        return Result.SUCCESS(200, "OK", data);
    }

    @Schema(defaultValue = "成功返回方法")
    public static <T> Result<T> SUCCESS(int code, String message, T data) {
        Result<T> result = new Result<>();
        result.setMessage(message);
        result.setCode(code);
        result.setData(data);
        return result;
    }

    @Schema(defaultValue = "失败返回方法")
    public static Result<Object> ERROR() {
        Result<Object> result = new Result<>();
        result.setMessage("失败");
        result.setCode(500);
        result.setData(null);
        return result;
    }

    @Schema(defaultValue = "失败返回方法")
    public static <T> Result<T> ERROR(String message) {
        return Result.ERROR(500, message, null);
    }

    @Schema(defaultValue = "失败返回方法")
    public static <T> Result<T> ERROR(int code, String message) {
        return Result.ERROR(code, message, null);
    }

    @Schema(defaultValue = "失败返回方法")
    public static <T> Result<T> ERROR(int code, String message, T data) {
        Result<T> result = new Result<>();
        result.setMessage(message);
        result.setCode(code);
        result.setData(data);
        return result;
    }
}
